<!--
 * @Descripttion: 
 * @Author: 彦祖·魏
 * @Date: 2020-08-06 17:15:50
 * @LastEditors: weishihao
 * @LastEditTime: 2020-08-06 17:17:22
-->
<template>
	<view class="body">
		<u-navbar :is-back="false" title="衣帮衣" title-color="#000">
			<view class="slot-wrap" @click="toMsg"><u-icon name="chat" size="50"></u-icon></view>
		</u-navbar>
		<!-- 	<view class="msg" v-show="msgShow">
			<div class="msg_centent">
				<u-icon name="volume-up" color="#F08929" size="30" class="volume"></u-icon>
				<text>办事项及通知：您有几个订单未确认，请立即处理！</text>
			</div>
			<div class="close" @click="msgShow = false"><u-icon name="close" color="#F08929" size="28"></u-icon></div>
		</view> -->
		<itemList @handleFn="handleFn"></itemList>
	</view>
</template>

<script>
import itemList from './components/item-list.vue';
export default {
	data() {
		return {
			msgShow: true
		};
	},
	onLoad() {
		// let value = uni.getStorageSync('token')
		//    if (!value) {
		//      uni.reLaunch({
		//        url: '/pages/login/login',
		//      })
		//    }
		console.log('onLoad');
		let value = uni.getStorageSync('token')
		if (!value) {
		  uni.reLaunch({
		    url: '/pages/login/login',
		  })
		}
	},
	onShow() {
		console.log('onLoad onShow');
	},
	onHide() {
		console.log('onLoad onHide');
	},
	components: {
		itemList
	},
	methods: {
		// 跳转消息列表页
		toMsg() {
			uni.navigateTo({
				url: './news/news'
			});
		},
		// 页面跳转判断
		handleFn({ flag, title } = obj) {
			switch (flag) {
				// 裁片发出
				case 'cpls':
					this.scanCode('cpls');
					break;
				// 查询工件
				case 'cxgj':
					this.scanCode('cxgj');
					break;
				// 快递查询
				case 'kdcx':
					uni.navigateTo({
						url: `./expressQuery/expressQuery`
					});
					break;
				// 水洗标查询
				case 'sxbcx':
					uni.navigateTo({
						url: `./searchWash/searchWash`
					});
					break;
				default:
					uni.navigateTo({
						url: `../scan/scan?flag=${flag}&title=${title}`
					});
			}
		},
		scanCode(flag) {
			// 只允许通过相机扫码
			uni.scanCode({
				onlyFromCamera: true,
				success: res => {
					if (flag == 'cpls') {
						this.getCut(res.result);
					} else if (flag == 'cxgj') {
						this.searchUnit(res.result);
					}
				}
			});
		},
		// 领取裁片
		getCut(unitNo) {
			this.$store.dispatch('getUnitDetail', { unitNo }).then(res => {
				if (res.errorCode == 0) {
					uni.navigateTo({
						url: './getCut/getCut'
					});
				}
			});
		},
		// 查询工件
		searchUnit(unitNo) {
			this.$store.dispatch('getUnitDetail', { unitNo }).then(res => {
				if (res.errorCode == 0) {
					uni.navigateTo({
						url: './queryWork/queryWork'
					});
				}
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.slot-wrap {
	display: flex;
	align-items: center;
	padding: 0 40rpx;
}
.body {
	border-top: 1rpx solid #f1f1f1;
}
.msg {
	display: flex;
	justify-content: space-between;
	align-items: center;
	background: #fff4c7;
	padding: 12rpx 0;
	.msg_centent {
		font-size: 24rpx;
		flex: 1;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		.volume {
			margin-right: 10rpx;
			margin-left: 30rpx;
		}
	}
	.close {
		padding: 0 30rpx;
	}
}
</style>
